package org.sny7.openOfflineList.listener;

import java.util.Map;

import javax.swing.ButtonGroup;
import javax.swing.JMenu;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;

import org.jvnet.substance.SubstanceLookAndFeel;
import org.jvnet.substance.skin.SkinInfo;
import org.sny7.openOfflineList.gui.SkinMenuItem;

public class SkinMenuClick implements MenuListener {

	public void menuCanceled(MenuEvent e) {
		
	}

	public void menuDeselected(MenuEvent e) {
		
	}

	public void menuSelected(MenuEvent e) {
		JMenu skinMenu = (JMenu) e.getSource();
		
		Map<String, SkinInfo> skinMap = SubstanceLookAndFeel.getAllSkins();
		ButtonGroup skinGroup = new ButtonGroup();
		String currentSkinClassName = SubstanceLookAndFeel.getCurrentSkin().getClass().getName();
		for (Map.Entry<String, SkinInfo> skin : skinMap.entrySet()) {
			String skinName = skin.getValue().getClassName();
			SkinMenuItem skinMenuItem = new SkinMenuItem();
			skinMenuItem.setText(skin.getKey());
			skinMenuItem.setSkinClass(skinName);
			skinMenuItem.addActionListener(new SkinMenuItemClick());
			if (currentSkinClassName.equals(skinName)) {
				skinMenuItem.setSelected(true);
			}
			skinGroup.add(skinMenuItem);
			skinMenu.add(skinMenuItem);
		}
		
		skinMenu.removeMenuListener(this);
	}

}
